package com.yh.csx.bsf.flow.dao.dal.auto;

import java.util.ArrayList;
import java.util.Map;
import java.util.List;

import com.yh.csx.bsf.flow.core.db.ConvertUtil;
import com.yh.csx.bsf.flow.core.db.DbConn;
import com.yh.csx.bsf.flow.dao.model.auto.*;

/** 代码自动生成工具自动生成,不要在这里写自己的代码，否则会被自动覆盖哦 - 车毅*/
public class t_approve_log_base_dal
{
    public boolean add(DbConn conn, t_approve_log_model model)
    {
		Object[] Par = new Object[]{
		
		//流程id
		model.flow_id,
		//任务id
		model.task_id,
		//审批结果
		model.result,
		//备注
		model.remark,
		//审批节点
		model.node,
		//审批人工号
		model.user_no,
		//
		model.create_time,
		//创建人
		model.create_by,
		//更新时间
		model.update_time,
		//更新人
		model.update_by,
		//审批人
		model.user_by
		};
        int rev = conn.executeSql("insert into t_approve_log(flow_id,task_id,result,remark,node,user_no,create_time,create_by,update_time,update_by,user_by)"+
										"values(?,?,?,?,?,?,?,?,?,?,?)", Par);
        return rev == 1;

    }

    public boolean edit(DbConn conn, t_approve_log_model model)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        
		//流程id
		Par.add(model.flow_id);
		//任务id
		Par.add(model.task_id);
		//审批结果
		Par.add(model.result);
		//备注
		Par.add(model.remark);
		//审批节点
		Par.add(model.node);
		//审批人工号
		Par.add(model.user_no);
		//
		Par.add(model.create_time);
		//创建人
		Par.add(model.create_by);
		//更新时间
		Par.add(model.update_time);
		//更新人
		Par.add(model.update_by);
		//审批人
		Par.add(model.user_by);
		Par.add(model.id);

        int rev = conn.executeSql("update t_approve_log set flow_id=?,task_id=?,result=?,remark=?,node=?,user_no=?,create_time=?,create_by=?,update_time=?,update_by=?,user_by=? where id=?",  Par.toArray());
        return rev == 1;

    }

    public boolean delete(DbConn conn, int id)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        Par.add(id);

        String Sql = "delete from t_approve_log where id=?";
        int rev = conn.executeSql(Sql, Par.toArray());
        if (rev == 1)
        {
            return true;
        }
        else
        {
            return false;
        }

    }

    public t_approve_log_model get(DbConn conn, int id)
    {
        ArrayList<Object> Par = new ArrayList<Object>();
        Par.add(id);
        StringBuilder stringSql = new StringBuilder();
        stringSql.append("select s.* from t_approve_log s where s.id=?");
        List<Map<String,Object>> ds = conn.executeList(stringSql.toString(), Par.toArray());
        if (ds != null && ds.size() > 0)
        {
			return createModel(ds.get(0));
        }
        return null;
    }

	public ArrayList<t_approve_log_model> list(DbConn conn)
    {
		ArrayList<t_approve_log_model> rs = new ArrayList<t_approve_log_model>();
        StringBuilder stringSql = new StringBuilder();
        stringSql.append("select s.* from t_approve_log s ");
        List<Map<String,Object>> ds = conn.executeList(stringSql.toString(), new Object[]{});
        if (ds != null && ds.size() > 0)
        {
			for (Map<String,Object> dr : ds)
			{
				rs.add(createModel(dr));
			}
        }
        return rs;
    }

	public t_approve_log_model createModel(Map<String,Object> dr)
    {
        t_approve_log_model o = new t_approve_log_model();
		
		//日志ID
		if(dr.containsKey("id"))
		{
			o.id = ConvertUtil.objToInt(dr.get("id"));
		}
		//流程id
		if(dr.containsKey("flow_id"))
		{
			o.flow_id = ConvertUtil.objToInt(dr.get("flow_id"));
		}
		//任务id
		if(dr.containsKey("task_id"))
		{
			o.task_id = ConvertUtil.objToInt(dr.get("task_id"));
		}
		//审批结果
		if(dr.containsKey("result"))
		{
			o.result = ConvertUtil.objToStr(dr.get("result"));
		}
		//备注
		if(dr.containsKey("remark"))
		{
			o.remark = ConvertUtil.objToStr(dr.get("remark"));
		}
		//审批节点
		if(dr.containsKey("node"))
		{
			o.node = ConvertUtil.objToStr(dr.get("node"));
		}
		//审批人工号
		if(dr.containsKey("user_no"))
		{
			o.user_no = ConvertUtil.objToStr(dr.get("user_no"));
		}
		//
		if(dr.containsKey("create_time"))
		{
			o.create_time = ConvertUtil.objToDateTime(dr.get("create_time"));
		}
		//创建人
		if(dr.containsKey("create_by"))
		{
			o.create_by = ConvertUtil.objToStr(dr.get("create_by"));
		}
		//更新时间
		if(dr.containsKey("update_time"))
		{
			o.update_time = ConvertUtil.objToDateTime(dr.get("update_time"));
		}
		//更新人
		if(dr.containsKey("update_by"))
		{
			o.update_by = ConvertUtil.objToStr(dr.get("update_by"));
		}
		//审批人
		if(dr.containsKey("user_by"))
		{
			o.user_by = ConvertUtil.objToStr(dr.get("user_by"));
		}
		return o;
    }
}
